KVM: do not allow mapping valid but non-reference-counted pages
authorNicholas Piggin <npiggin@gmail.com>
Thu, 24 Jun 2021 12:29:04 +0000 (08:29 -0400)
committerSalvatore Bonaccorso <carnil@debian.org>
Thu, 23 Sep 2021 20:35:21 +0000 (21:35 +0100)
commit8fc0f721991b9461f9ab950e1c67b2104e6e0731
treea78b643c333b94bac4bf69efd89a79f3d054ec60
parent674fd7e36e043e27c6cca80fbd7b4d6e1e6ed005
KVM: do not allow mapping valid but non-reference-counted pages

Origin: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit?id=dd8ed6c9bc2224c1ace5292d01089d3feb7ebbc3
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2021-22543

commit f8be156be163a052a067306417cd0ff679068c97 upstream.

It's possible to create a region which maps valid but non-refcounted
pages (e.g., tail pages of non-compound higher order allocations). These
host pages can then be returned by gfn_to_page, gfn_to_pfn, etc., family
of APIs, which take a reference to the page, which takes it from 0 to 1.
When the reference is dropped, this will free the page incorrectly.

Fix this by only taking a reference on valid pages if it was non-zero,
which indicates it is participating in normal refcounting (and can be
released with put_page).

This addresses CVE-2021-22543.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Tested-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name KVM-do-not-allow-mapping-valid-but-non-reference-cou.patch
virt/kvm/kvm_main.c